﻿@{
    ViewBag.Title = "RechargeRule";
}
@{
    ViewBag.Title = "Member";
}
@section scripts
{
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>     
    <script src="@Url.Content("~/Scripts/common/export.js")" type="text/javascript"></script>
}       
     @Html.Partial("~/Views/Modular/ToolBarBaseEx.cshtml")

    <div class="mini-fit" >
        <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" pageSize="15"
                borderStyle="border:1;" url="../Member/GetRuleList"
                allowCellSelect="true" allowCellEdit="true"showColumnsMenu="true"fitColumns="false"  
                onrowdblclick="modify"  sortMode="client">
            <div property="columns">
                <div type="checkcolumn" >选行</div>
                <div type="indexcolumn" width="40" headerAlign="center" >序号</div>
                <div field="FName" name="FName" width="100" headeralign="center" allowsort="true">会员分类</div>
                <div field="FBeginTime" name="FBeginTime" width="120" headeralign="center"  allowsort="true" dateFormat="yyyy-MM-dd" >开始时间</div>
                <div field="FEndTime" name="FEndTime" width="120" headeralign="center"  allowsort="true" dateFormat="yyyy-MM-dd" >结束时间</div>
                <div field="FAmount" name="FAmount" width="70" headeralign="center" allowsort="true" align="right" NumberFormat="#,0.00">充值金额</div>
                <div field="FGiveAmt" name="FGiveAmt" width="70" headeralign="center" allowsort="true" align="right" NumberFormat="#,0.00">赠送金额</div>
                <div field="FCouponNumber" name="FCouponNumber" width="100" headeralign="center" allowsort="true">赠送卡券编码</div>
                <div field="FCouponName" name="FCouponName" width="100" headeralign="center" allowsort="true">赠送卡券名称</div>
                <div field="FCouponQty" name="FCouponQty" width="90" headeralign="center" allowsort="true" align="right" NumberFormat="#">赠送卡券数量</div>
                <div field="FTypeName" name="FTypeName" width="100" headeralign="center" allowsort="true">充值类型</div>
                <div field="FStateName" name="FStateName" width="70" headeralign="center"  align="center" allowsort="true">状态</div>
                <div field="FAddingName" name="FAddingName" width="70" headeralign="center"  align="center" allowsort="true">是否累加</div>
                <div field="FRemark" name="FRemark" width="100" headeralign="center"  allowsort="true">备注</div>
            </div>
        </div>
    </div>

<script>
    mini.parse();
    var grid = mini.get("datagrid1");
    var dataList = [];

    function FormShown() {
        LoadListData();
    }

    //加载资料列表
    function LoadListData() {
        var sSystemAppID = parent.window.getSystemAppID();
            var json = "[{";
            json = json + '"FSystemAppID":' + '"' + sSystemAppID + '"';
            json = json + "}]";
            grid.load({ mjson: json });

            mExportDataUrl = grid.url;
            mExportDataJson = json;
    }

    //搜索资料列表
    function search() {
        LoadListData();
    }


    ///增加资料
    function newBill() {
        var uID = parent.window.getSystemAppID();
        mini.open({
            url: "/Member/RuleInfo",
            title: "充值规则", width: 650, height: 450,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "new", FItemID: "0"};
                iframe.contentWindow.SetInfoData(data);
            },
            ondestroy: function (action) {
                grid.reload();
            }
        });
    }

    //修改资料
    function modify() {
        if (!mini.get("edit").getVisible()) return;
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "/member/RuleInfo",
                title: "充值规则", width: 650, height: 450,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = {
                        action: "edit", FItemID: row.FItemID
                    };
                    iframe.contentWindow.SetInfoData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });

        } else {
            mini.alert("请选中一条记录");
        }
    }

    function removeInfo() {
        var row = grid.getSelected();
        if (row) {
            mini.confirm("确定要删除选中的记录吗？", "提示",
                function (action) {
                    if (action == "ok") {
                        SetRemoveRows();
                    }
                });
        } else {
            mini.alert("请选要删除的记录");
        }
    }

    function SetRemoveRows() {
        var FSystemAppID = parent.window.getSystemAppID();
        var rows = grid.getSelecteds();
        var json = "[";
        for (var i = 0; i < rows.length; i++) {
                if (i > 0) json = json + ',';
                js = '{"FItemID":' + rows[i].FItemID + '}';
                json = json + js
        }
        json = json + "]";
        if (json.length < 8) {
            mini.alert("没有要保存的数据！");
            return;
        }
        $.post("RemoveRule", { json: json, mSystemAppID: FSystemAppID }, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                grid.reload();
            }
            else {
                mini.alert("出现错误，错误信息:" + ret.error);
            }
        });
    }

    function printBill() {
        var url = "../Report/PrintReport";
        mini.open({
            url: url,
            title: "打印", width: 1000, height: 700,
            onload: function () {
                var iframe = this.getIFrameEl();
                var NoneDisplayCol = [0];
                iframe.contentWindow.InitalPrint(grid, NoneDisplayCol, parent.window.getSystemCompany() + "充值规则表");
            }
        });
    }

</script>
